package cn.xyfmzmy.chain.validation;


import cn.xyfmzmy.chain.exception.ValidationException;

public class LengthValidateHandler implements ValidateHandler{

    private final int length;

    public LengthValidateHandler(int length) {
        this.length = length;
    }

    @Override
    public void validate(Object value,ValidateContext validateContext) {
        if(value instanceof String strValue){
            if(strValue.length() > length){
                validateContext.appendError("你的值的长度是" + strValue.length() + "不能大于" + length);
            }
        }
    }
}
